part of 'card.dart';

class _UnspecifiedLexicalItemObscureCardWloc extends StatefulWloc<
    _UnspecifiedLexicalItemObscureCardWlocState,
    UnspecifiedLexicalItemObscureCard> with CardWlocMixin {
  late final bloc.UnspecifiedLexicalItemObscureCardBloc _bloc;

  @override
  _UnspecifiedLexicalItemObscureCardWlocState get initialState {
    return _UnspecifiedLexicalItemObscureCardWlocState(
      lexicalItem: widget.lexicalItem,
      dialect: widget.dialect,
      safeToPronounce: widget.safeToPronounce,
    );
  }

  void onPronunciationCautionButtonPressed() {
    showPronunciationCautionDialog(
      context: context,
    );
  }

  void onLexicalItemPronunciationButtonPressed() {
    _bloc.requestLexicalItemPronunciation();
  }

  void onExposureButtonPressed() {
    widget.onExposureButtonPressed();
  }

  void onLexicalItemUseCasePronunciationButtonPressed(LexicalItemUseCase lexicalItemUseCase) {
    _bloc.requestLexicalItemUseCasePronunciation(
      lexicalItemUseCase: lexicalItemUseCase,
    );
  }

  @override
  void initState() {
    super.initState();

    _bloc = bloc.UnspecifiedLexicalItemObscureCardBloc(
      lexicalItem: widget.lexicalItem,
      pronounceLexicalItem: unspecified_lexical_item_obscure_card_di.sl(),
      pronounceLexicalItemUseCase: unspecified_lexical_item_obscure_card_di.sl(),
    );
  }

  @override
  void didUpdateWidget(UnspecifiedLexicalItemObscureCard oldWidget) {
    super.didUpdateWidget(oldWidget);

    final updatedState = _UnspecifiedLexicalItemObscureCardWlocState(
      lexicalItem: widget.lexicalItem,
      dialect: widget.dialect,
      safeToPronounce: widget.safeToPronounce,
    );

    emit(updatedState);

    if (oldWidget.lexicalItem != widget.lexicalItem) {
      _bloc.updateLexicalItem(
        lexicalItem: widget.lexicalItem,
      );
    }
  }

  @override
  void dispose() {
    _bloc.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return _UnspecifiedLexicalItemObscureCardView(
      wloc: this,
    );
  }
}
